package exp09dfsbfs;

//多项式控件
public class DepthFirstSearching {
    //递归程序
    static int n = 9;
    static int[] book = new int[n];
    static int[] arr = new int[n];


    static void dfs(int k) {
        if (k >= n) {
            //System.out.println(Arrays.toString(arr));
            int X = 100 * arr[0] + 10 * arr[1] + arr[2];
            int Y = 100 * arr[3] + 10 * arr[4] + arr[5];
            int Z = 100 * arr[6] + 10 * arr[7] + arr[8];
            if (2 * X == Y && 3 * X == Z) {
                System.out.println(String.format("%d %d %d", X, Y, Z));
            }
            return;
        }
        for (int i = 0; i < n; i++) {
            if (book[i] == 1) continue;
            arr[k] = i + 1;

            book[i] = 1;
            dfs(k + 1);
            book[i] = 0;
        }
    }

    public static void main(String[] args) {
        dfs(0);
    }
}
